<?php

class SiteController extends Controller
{
    /**
     * Declares class-based actions.
     */
    public function actions()
    {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex()
    {
        //newest product
        $bannerTop = CContents::model()->findAll("COMN_CODE = 'TOP_BANNER' AND USE_YN = 'Y' ORDER BY SORT_ORDER");
        $brands = CContents::model()->findAll("COMN_CODE = 'WEB_BRAND' AND USE_YN = 'Y' ORDER BY SORT_ORDER ");
        $newest = Yii::app()->db->createCommand()
            ->from('vw_group_products gp')
            ->where('RECORD_TYPE = \'LASTEST\'')
            ->queryAll();
        $featured = Yii::app()->db->createCommand()
            ->from('vw_group_products gp')
            ->where('RECORD_TYPE = \'FEATURED\'')
            ->queryAll();
        $bestSelling = Yii::app()->db->createCommand()
            ->from('vw_group_products gp')
            ->where('RECORD_TYPE = \'BEST_SELLER\'')
            ->queryAll();

        $this->render('index', array('lasts' => $newest, 'featured' => $featured,
            'bestSells' => $bestSelling, 'bannerTop' => $bannerTop, 'brands' => $brands));
    }

    /**
     * This is the action to handle external exceptions.
     */
    public function actionError()
    {
        if ($error = Yii::app()->errorHandler->error) {
            $this->render('error', $error);
        }
    }

    /**
     * Displays the contact page
     */
    public function actionContact()
    {

        $this->render('contact');
    }


}